package cn.tangwei.org.service;

import cn.tangwei.BaseTest;
import org.junit.Test;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.mail.SimpleMailMessage;
import org.springframework.mail.javamail.JavaMailSender;
import org.springframework.mail.javamail.MimeMailMessage;
import org.springframework.mail.javamail.MimeMessageHelper;

import javax.mail.MessagingException;
import javax.mail.internet.MimeMessage;
import java.io.File;

/**
 * 继承抽取的测试类注解
 */
public class EmailTset extends BaseTest {
    @Autowired
    private JavaMailSender javaMailSender;

    /**
     * 发送简单邮件
     */
    @Test
    public void send1(){
        SimpleMailMessage mailMessage = new SimpleMailMessage();
        // 设置发件人
        mailMessage.setFrom("2682460963@qq.com");
        // 设置发送主题
        mailMessage.setSubject("洗脚");
        // 设置发送内容
        mailMessage.setText("成都洗脚店开门了");
        // 设置收件人
        mailMessage.setTo("514408236@qq.com");
        javaMailSender.send(mailMessage);
    }
    
    @Test
    public void send2() throws MessagingException {
        // 创建复杂邮件对象
        MimeMessage mimeMessage = javaMailSender.createMimeMessage();
        // 发送复杂邮件工具类
        MimeMessageHelper mimeMessageHelper = new MimeMessageHelper(mimeMessage, true, "UTF-8");
        mimeMessageHelper.setFrom("2682460963@qq.com");
        mimeMessageHelper.setSubject("测试指南");
        mimeMessageHelper.setText("测试网络图片" + "<img src='http://47.95.117.210:8888/group1/M00/00/56/rBE3kWDa_N2AeGfRAAB6kSvOw5Y785.jpg'/>", true);
        //添加附件
        mimeMessageHelper.addAttachment("罗宾.jpg",new File("E:\\图片\\04_images\\photos\\1622596162289.jpg"));
        //收件人
        mimeMessageHelper.setTo("514408236@qq.com");
        javaMailSender.send(mimeMessage);
    }
}
